home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / DR / DR_TEST.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  2KB  |  94 lines

  1. /*************************************************************************
  2.  
  3.     dr_test.c       Directory (dr) subroutines
  4.             for Bywater Software.
  5.  
  6.             Test program
  7.  
  8.             Copyright (c) 1991, Ted A. Campbell
  9.  
  10.             Bywater Software
  11.             P. O. Box 4023 
  12.             Duke Station 
  13.             Durham, NC  27706
  14.  
  15.             email: tcamp@hercules.acpub.duke.edu
  16.  
  17.     Copyright and Permissions Information:
  18.  
  19.     All U.S. and international copyrights are claimed by the
  20.     author. The author grants permission to use this code
  21.     and software based on it under the following conditions:
  22.     (a) in general, the code and software based upon it may be 
  23.     used by individuals and by non-profit organizations; (b) it
  24.     may also be utilized by governmental agencies in any country,
  25.     with the exception of military agencies; (c) the code and/or
  26.     software based upon it may not be sold for a profit without
  27.     an explicit and specific permission from the author, except
  28.     that a minimal fee may be charged for media on which it is
  29.     copied, and for copying and handling; (d) the code must be 
  30.     distributed in the form in which it has been released by the
  31.     author; and (e) the code and software based upon it may not 
  32.     be used for illegal activities. 
  33.  
  34. **************************************************************************/
  35.  
  36. #include "stdio.h"
  37. #ifdef    __STDC__
  38. #include "malloc.h"
  39. #else
  40. extern    char *malloc();
  41. #endif
  42. #include "dr.h"
  43.  
  44. #define    DIR_ENTRIES    128
  45.  
  46. char findname[ MAX_PATHLENGTH ];
  47. struct dir_ent *retstructs[ DIR_ENTRIES ];
  48.  
  49. main()
  50.     {
  51.     register int c;
  52.  
  53.     for ( c = 0; c < DIR_ENTRIES; ++c )
  54.         {
  55.         if ( ( retstructs[ c ] 
  56.             = (struct dir_ent *) malloc( sizeof( struct dir_ent )) ) == NULL )
  57.             {
  58.             fprintf( stderr, "Failed to allocate memory for directory structure.\n" );
  59.             exit( 1 );
  60.             }
  61.         }
  62.  
  63.     printf( "Enter an ambiguous file specifier:  " );
  64.     gets( findname );
  65. /*    printf( "\n" ); */
  66.  
  67.     c = 0;
  68.     if ( dr_first( findname, retstructs[ c ] ) == 0 )
  69.         {
  70.         printf( "No matches found.\n" );
  71.         exit( 1 );
  72.         }
  73.  
  74.  
  75.     printf( "Pathname: %s\tFilename: %s\tType: %d\tSize: %ld\n",
  76.         retstructs[ c ]->pathname,
  77.         retstructs[ c ]->filename,
  78.         retstructs[ c ]->type,
  79.         retstructs[ c ]->size );
  80.     ++c; 
  81.  
  82.     while( dr_next( retstructs[ c ] ) != 0 )
  83.         {
  84.         printf( "Pathname: %s\tFilename: %s\tType: %d\tSize: %ld\n",
  85.             retstructs[ c ]->pathname,
  86.             retstructs[ c ]->filename,
  87.             retstructs[ c ]->type,
  88.             retstructs[ c ]->size );
  89.         ++c;
  90.         }
  91.     }
  92.  
  93.  
  94.